package com.ruoyi.tb.lmt.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import com.ruoyi.tb.lmt.domain.bo.TbLmtrepairWorkdetailBo;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.tb.lmt.domain.vo.TbWorkFileVo;
import com.ruoyi.tb.lmt.domain.bo.TbWorkFileBo;
import com.ruoyi.tb.lmt.service.ITbWorkFileService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 大机履历资料
 *
 * @author ruoyi
 * @date 2024-02-01
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/xha-lmt/workFile")
public class TbWorkFileController extends BaseController {

    private final ITbWorkFileService iTbWorkFileService;

    /**
     * 查询大机履历资料列表
     */
    @SaCheckPermission("xha-lmt:workFile:list")
    @GetMapping("/list")
    public TableDataInfo<TbWorkFileVo> list(TbWorkFileBo bo, PageQuery pageQuery) {
        return iTbWorkFileService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出大机履历资料列表
     */
    @SaCheckPermission("xha-lmt:workFile:export")
    @Log(title = "大机履历资料", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(TbWorkFileBo bo, HttpServletResponse response) {
        List<TbWorkFileVo> list = iTbWorkFileService.queryList(bo);
        ExcelUtil.exportExcel(list, "大机履历资料", TbWorkFileVo.class, response);
    }

    /**
     * 获取大机履历资料详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("xha-lmt:workFile:query")
    @GetMapping("/{id}")
    public R<TbWorkFileVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iTbWorkFileService.queryById(id));
    }

    /**
     * 新增大机履历资料
     */
    @SaCheckPermission("xha-lmt:workFile:add")
    @Log(title = "大机履历资料", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody TbWorkFileBo bo) {
        return toAjax(iTbWorkFileService.insertByBo(bo));
    }

    /**
     * 修改大机履历资料
     */
    @SaCheckPermission("xha-lmt:workFile:edit")
    @Log(title = "大机履历资料", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody TbWorkFileBo bo) {
        return toAjax(iTbWorkFileService.updateByBo(bo));
    }

    /**
     * 删除大机履历资料
     *
     * @param ids 主键串
     */
    @SaCheckPermission("xha-lmt:lmtrepairWorkdetail:delete")
    @Log(title = "大机履历资料", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iTbWorkFileService.deleteWithValidByIds(Arrays.asList(ids), true));
    }


    /**
     * 批量增加大机履历资料
     */
    @SaCheckPermission("xha-lmt:workFile:addList")
    @PostMapping("addList")
    public R<?> addList(@Validated(EditGroup.class) @RequestBody List<TbWorkFileBo> bos) {
        for (TbWorkFileBo bo : bos) {
            iTbWorkFileService.insertByBo(bo);
        }
        return R.ok();
    }
}
